Skip to content

fix: prevent home page crash when latest feed returns 403#63

Merged
justinhartman merged 2 commits intodevelopfrom
feat/fix-403-error-on-index-page
Feb 24, 2026
Merged

fix: prevent home page crash when latest feed returns 403#63
justinhartman merged 2 commits intodevelopfrom
feat/fix-403-error-on-index-page

Conversation

@justinhartman
Copy link
Owner

Motivation

  • The index route crashed when one of the upstream latest-feed endpoints returned a non-2xx response (e.g. HTTP 403) because both requests were awaited via Promise.all and an Axios error propagated.
  • Route handlers also needed to be robust against Express req.params being string | string[] to avoid TypeScript and runtime issues.

Description

  • Switched home-page latest content fetches to Promise.allSettled and treat each feed independently so a failing feed falls back to an empty array while successful feeds still render.
  • Added lightweight warning output (console.warn) when a latest-feed fetch is rejected to aid troubleshooting without interrupting rendering.
  • Normalized route param extraction in getView by coercing req.params.id, req.params.season, and req.params.episode to strings when an array is present to prevent string | string[] type errors.
  • Added a unit test getHome handles upstream failures without crashing that simulates one rejected feed and verifies the page still renders with partial data.

Testing

  • Ran yarn test controllers/appController.spec.ts --runInBand and the spec file passed (17 passed).
  • Ran yarn lint:ts in this environment but it fails due to missing type definition files for jest/node, which is unrelated to the functional change in this PR.

Codex Task

@vercel
Copy link

vercel bot commented Feb 24, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
imdb-app Ready Ready Preview, Comment Feb 24, 2026 10:59pm

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8e915b7a61

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +90 to +93
let newMovies =
movieResult.status === 'fulfilled' ? movieResult.value.data.result || [] : [];
let newSeries =
seriesResult.status === 'fulfilled' ? seriesResult.value.data.result || [] : [];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Avoid caching fallback empties after partial feed failures

When one upstream latest-feed call fails, these lines coerce that dataset to [], and the handler still executes setLatest({ movies: newMovies, series: newSeries }) afterward; because helpers/cache.ts sets a 24-hour TTL, a transient 403/timeout can leave the home page missing movies or series for an entire day even after the API recovers. Consider skipping cache writes (or using a much shorter TTL) when either Promise.allSettled result is rejected.

Useful? React with 👍 / 👎.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codex fix

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

  • Updated getHome to avoid writing to the 24-hour latest cache when either upstream latest-feed request fails; it now computes hasFeedFailure from the Promise.allSettled results and only calls setLatest when both requests are fulfilled. This preserves resilient rendering while preventing stale partial data from being cached. controllers/appController.tsL85-L113
  • Added/updated test coverage to assert setLatest is not called when one latest-feed request rejects, guarding against regressions for the reviewer-reported scenario. controllers/appController.spec.tsL97-L117
  • Committed the change on the current branch with Conventional Commit message: fix: skip cache write on partial latest-feed failures (commit 2ef24f8).

Testing

  • ⚠️ curl -I https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled | head (network/proxy returned HTTP 403 in this environment).
  • yarn test controllers/appController.spec.ts --runInBand

Also completed the required PR handoff step via make_pr with title “fix: avoid caching partial latest-feed fallbacks” and a body summarizing these follow-up changes.

View task →

@codecov
Copy link

codecov bot commented Feb 24, 2026

Codecov Report

❌ Patch coverage is 73.07692% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 99.62%. Comparing base (b1c04c0) to head (187a3ea).
⚠️ Report is 3 commits behind head on develop.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
controllers/appController.ts 73.07% 6 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop      #63      +/-   ##
===========================================
- Coverage   100.00%   99.62%   -0.38%     
===========================================
  Files           21       21              
  Lines         1844     1863      +19     
  Branches       154      163       +9     
===========================================
+ Hits          1844     1856      +12     
- Misses           0        6       +6     
- Partials         0        1       +1     
Flag Coverage Δ
tests 99.62% <73.07%> (-0.38%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@justinhartman justinhartman merged commit 4c2fc70 into develop Feb 24, 2026
3 checks passed
@justinhartman justinhartman deleted the feat/fix-403-error-on-index-page branch February 24, 2026 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant